import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: "",
    isLogin: true,
    user: {
      userId: "6543210",
      userHead:
        "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1595233833221&di=8cf8621bb5bdae4844362dfe99c54191&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fbd315c6034a85edf8c1758e240540923dc547553.jpg",
      nickName: "undefined",
      isNewContent: false,
      isEnterprise: true,
    },
    isOpenScreenShow: false,
    lang: "zh-CN",
    copyright: "2020 test",
  },
  mutations: {
    updateLang(state, v) {
      state.lang = v;
      localStorage.setItem("siteLang", v);
    },
    openScreenShow(state, v) {
      state.isOpenScreenShow = v;
    },
    updateToken(state) {
      let v = Vue.$Cookie("token");
      if (v) {
        state.token = v;
        state.isLogin = true;
      } else {
        state.token = "";
        state.isLogin = false;
      }
    },
    writeToken(state, v) {
      Vue.$Cookie("token", v);
      state.token = v;
      state.isLogin = true;
    },
  },
  actions: {},
  modules: {},
});
